/***
 *新闻列表
 * XYB
 * ***/
SPA_RESOLVE_INIT = function(transition) {
    var html = '<table class="Table_common newsListTab mt-20">\n' +
        '<thead>\n' +
        '<tr>\n' +
        '<td>id</td>\n' +
        '<td>标题</td>\n' +
        '<td>时间</td>\n' +
        '<td>操作</td>\n' +
        '</tr>\n' +
        '</thead>\n' +
        '<tbody id="newsListTabs"></tbody>\n' +
        '</table>\n' +
        '<div class="paging-area-box mt-10 magin-auto">\n' +
        '<div class="paging-area float-left" id="pagination"></div>\n' +
        '<span class="pageNum float-right f-14">共<em>0</em>条数据</span>\n' +
        '</div>';

    html += '<style>\n' +
        ' \n' +
        ' .newsListTab tr td:nth-child(2){\n' +
        'border-left:1px solid #333;\n' +
        'border-right:1px solid #333;\n' +
        '}\n' +
        '.newsListTab tr td:nth-child(3){\n' +
        'border-right:1px solid #333;\n' +
        '}\n' +
        '\n' +
        '</style>';
    getHref_path();
    $(".menu ul").hide();
    $(".menu ul").eq(0).show();
    document.getElementById("ui-right-content").innerHTML = html;
    newsListFun(1);
}

function newsListFun(pageNo){
    var id = window.document.getElementById("newsListTabs");
    $.ajax({
        url: get_newsAll_interface+'?currentPage='+pageNo,
        type:'get',
        dataType:'json',
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:{
            currentPage:pageNo
        },
        success: function(data) {
            if(data.code==200){
                inner_newsList_Tbody(data,id, newsListFun);
            }else{
                $.message(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}
function inner_newsList_Tbody(data,id, func){
    var page = data.data.num;
    var currentPage = data.data.currentPage;
    var tml = "";
    $(".pageNum em").html(page);
    if(page>0){
        setPagination(page,currentPage, func);
        var lists = data.data.list;
        $('#pagination').show();
        for (x in lists) {
            tml += "<tr>"+
                '<td>'+lists[x]["id"]+'</td>'+
                '<td>'+lists[x]["title"]+'</td>'+
                "<td>"+lists[x]["newsCreateTime"]+"</td>"+
                '<td><a href="javascript:;" class="c-009 f-14" onclick="hrefupdate(this)" data-newId="'+lists[x]["id"]+'" data-title="'+lists[x]["newsTitle"]+'" data-cont="'+lists[x]["newsContent"]+'">编辑</a>/' +
                '<a href="javascript:;" class="c-009 f-14" onclick="deleteNewsId(this)" data-newId="'+lists[x]["id"]+'">删除</a></td>'+
                "</tr>" ;
        }
    }else{
        $('#pagination').hide();
    }
    id.innerHTML = tml;
}

/**删除***/
function deleteNewsId(obj){
    var newsId = $(obj).attr("data-newId");
    $.ajax({
        url: delete_news_interface,
        type:'post',
        dataType:'json',
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:{
            newsId:newsId
        },
        success: function(data) {
            if(data.code==200){
                $.message("删除成功");
                $(obj).closest("tr").remove();
            }else{
                $.message(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}

function hrefupdate(obj) {
    var newsId =$(obj).attr("data-newId");
    location.href="?newsId="+newsId.toString()+"#/updatenews"
}